package com.atguigu.validator.four;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class CannotBlankValidation implements ConstraintValidator<CannotBlank, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value!=null && value.contains(" ")){
            String defaltConstraintMessageTemplate = context.getDefaultConstraintMessageTemplate();
            System.out.println(defaltConstraintMessageTemplate);
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate("不能空格").addConstraintViolation();
            return false;
        }
        return true;
    }
}
